
function bindEvent_service(){
    var cityUrl = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';
    $.getScript(cityUrl, function(script, textStatus, jqXHR) {
        if(remote_ip_info && remote_ip_info.city){
            $(".service_now_city").text(remote_ip_info.city);
        }else{
            $(".service_now_city").text('全国');
        }
    })
    $(".car_baoxian").click(function(){
        if(!$('#baoxian_page').length>0){
            $("body").append(html_content.baoxian);
        }
        $("#"+page_index[page_index.length-1]).hide();
        $("#baoxian_page").show();
        page_index.push("baoxian_page");
        $('body').attr('class','search_body')
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006 
        });      
    });
    $(".car_baoyang").click(function(){
        if(!$('#baoyang_page').length>0){
            $("body").append(html_content.baoyang);
        }
        $("#"+page_index[page_index.length-1]).hide();
        $("#baoyang_page").show();
        page_index.push("baoyang_page");
        $('body').attr('class','search_body') 
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006 
        });     
    });

    $(".dingdan_service").on("click",function(){
        $(".car_process").toggle();
    })
    mui('body').on('tap','.dingdan_service',function(e){
        this.click()
    })
    mui('body').on('tap','.service_sure_get',function(e){
        this.click()
    })
    mui('body').on('tap','.car_baoxian',function(e){
        this.click()
    })
    mui('body').on('tap','.car_baoyang',function(e){
        this.click()
    })
    
    $(".service_sure_get").click(function(){
        var orderid=$('.service_sure_get').attr('orderid');
        var spinner = new Spinner();   
        $.ajax({
            type: "POST",
            url: webConfig.url+"/Home/Index/setUserOrder",
            data: {orderid:orderid},
            dataType: "JSONP",
            crossDomain: true,
            beforeSend:function(){
                // $('#loadingBox').removeClass('hidden')
                // var target = document.getElementById('loadingBox');
                // spinner.spin(target)
            },
            complete:function(){
                // $('#loadingBox').addClass('hidden')
                // spinner.spin()
            },
            success: function(data){
               getUserOrder()
               
            },
            error:function(){
                
            }
        });
    });
}
mui('body').on('tap','.go_newcar_click',function(e){
    //追加显示新车页面
    if(!$('#newcar_page').length>0){
        $("body").append(html_content.newcar);
        bindEvent_newcar()
        bindPull_newcar()
    }
    newcar_page=1
    getNewCarData();
    $("#"+page_index[page_index.length-1]).hide();
    page_index.splice(page_index.length-1,1)
    $("#newcar_page").show();
    page_index[0]="newcar_page";
})
function bindPull_service(){
    mui('#service-list').pullRefresh({
        container: '#service-list',
        down: {
            contentdown : "下拉可以刷新",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
            contentover : "释放立即刷新",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
            callback: pulldownRefresh_service
        },
    });
}
function pulldownRefresh_service(){
    getUserOrder()
}
function getUserOrder(){
    var mobilephone=getLoginPhone();
    if(mobilephone){
        var spinner = new Spinner();   
        $.ajax({
            type: "POST",
            url: webConfig.url+"/Home/Index/getUserOrder",
            data: {mobilephone:mobilephone},
            dataType: "JSONP",
            crossDomain: true,
            beforeSend:function(){
                // $('#loadingBox').removeClass('hidden')
                // var target = document.getElementById('loadingBox');
                // spinner.spin(target)
            },
            complete:function(){
                // $('#loadingBox').addClass('hidden')
                // spinner.spin()
            },
            success: function(data){
                $(".dingdan_service").addClass('hidden');
                $('.pay_tishi_service').addClass('hidden');
                $(".service_no_car").removeClass('hidden');

                if(data['order']){
                    $(".service_no_car").addClass('hidden');
                    $(".dingdan_service").removeClass('hidden');
                    $(".service_sure_get").addClass('hidden');
                    // $(".order_over_time").addClass('hidden');
                    var status_content="交易中"
                    if(data['order']['status']=="6"){
                        show_evaluate(2,data['order']['orderid'])
                        // $(".order_over_time").removeClass('hidden');
                        // $('.order_last_pay_time').text(data['order']['last_pay_time']);
                        $('.order_finish_time').text(data['order']['finish_time']);
                        status_content="已完成";
                        var status=4;
                    }else if(data['order']['status']=="5"){
                        $('.service_sure_get').removeClass('hidden');
                        $('.service_sure_get').attr('orderid',data['order']['orderid'])
                        var status=3;
                    }else if(data['order']['status']=="4"){
                        
                        var status=2;
                    }else if(data['order']['status']=="2" || data['order']['status']=="3"){
                        if(data['order']['status']=="2"){
                            show_evaluate(1,data['order']['orderid'])
                        }
                        var status=1;
                    }else{
                        var status=0;
                    }
                    $('.order_status').text(status_content);
                    $('.order_num').text("订单"+data['order']['orderid']);
                    $('.order_carname').text(data['order']['carname']);
                    $('.order_car_num').text(data['order']['car_num']);
                    $('.order_car_color').text(data['order']['color']);
                    var guide_price=getMoneyText(data['order']['guide_price']);
                    var jdc_price=getMoneyText(data['order']['jdc_price']);
                    $('.order_guide_price').text(guide_price);
                    $('.order_jdc_price').text(jdc_price);
                    $('.order_first_pay').text("服务费："+getMoneyText(data['order']['first_pay']));
                    $('.order_month_pay').text("月租金："+parseInt(data['order']['month_pay'])+'元');
                    $('.order_tel').text(data['order']['tel']);
                    for(var i=0;i<=4;i++){
                        if($('.car_process_ul').find('li').eq(i).hasClass("color_active")){
                           $('.car_process_ul').find('li').eq(i).removeClass("color_active"); 
                        }
                        
                    }
                    for(var i=0;i<=status;i++){
                        $('.car_process_ul').find('li').eq(i).addClass("color_active"); 
                    }
                    for(var i=0;i<=8;i++){
                        if($('.yuan_xian').find('li').eq(i).hasClass("color_yuan_xian")){
                           $('.yuan_xian').find('li').eq(i).removeClass("color_yuan_xian"); 
                        } 
                    }
                    for(var i=0;i<=status;i++){
                        if(i>0){
                            $('.yuan_xian').find('li').eq(2*i-1).addClass("color_yuan_xian");
                        }
                        $('.yuan_xian').find('li').eq(2*i).addClass("color_yuan_xian");
                    }
               } 
               if(data['orderPay']){
                    $('.pay_tishi_service').removeClass('hidden');
                    $('.order_next_pay').text(parseInt(data['orderPay']['next_pay']));
                    if(data['orderPay']['next_pay_days']>=0){
                        $('.order_next_pay_days').text(data['orderPay']['next_pay_days']);
                        $('.order_next_text').text('距离还款时间');
                    }else{
                        $('.order_next_pay_days').text(0-data['orderPay']['next_pay_days']);
                        $('.order_next_text').text('逾期');
                    }
                    
                    $('.order_banknum').text(data['orderPay']['banknum']);
                    $('.order_pay_month').text(data['orderPay']['pay_month']);
                    $('.order_paymoney').text(parseInt(data['orderPay']['paymoney']));
               }
                mui('#service-list').pullRefresh().endPulldownToRefresh(); //refresh completed加载数据true为加载完毕false为未加载完毕
                
            },
            error:function(){
                $(".dingdan_service").addClass('hidden');
                $('.pay_tishi_service').addClass('hidden');
                $(".service_no_car").removeClass('hidden');
                mui('#service-list').pullRefresh().endPulldownToRefresh(); //refresh completed加载数据true为加载完毕false为未加载完毕
            }
        });
    
    }else{
        $(".dingdan_service").addClass('hidden');
        $('.pay_tishi_service').addClass('hidden');
        $(".service_no_car").removeClass('hidden');
        mui('#service-list').pullRefresh().endPulldownToRefresh();
    }
}
